//
//  MWBaseController.m
//  XiRan-iOS
//
//  Created by Richfit on 2019/10/10.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWBaseController.h"

@interface MWBaseController ()
@end

@implementation MWBaseController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChange:) name:kNetWorkStatusNotification object:nil];
    self.view.backgroundColor = MWHexColor(@"#ECF9FF");
    self.isFirst = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.isFirst = NO;
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)networkChange:(NSNotification *)notification {
}

- (UIImageView *)errorImageView {
    if (_errorImageView == nil) {
        _errorImageView = [[UIImageView alloc] init];
        _errorImageView.image = [UIImage imageNamed:@"icon_error"];
        _errorImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh)];
        [_errorImageView addGestureRecognizer:tap];
        [self.view addSubview:_errorImageView];
        
        [_errorImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.view);
            make.centerX.equalTo(self.view);
            make.width.equalTo(@150);
            make.height.equalTo(@(150 * 183 / 291));
        }];
        
    }
    return _errorImageView;
}

- (void)refresh {
    
}

- (UILabel *)errorTitleLabel {
    if (_errorTitleLabel == nil) {
        _errorTitleLabel = [[UILabel alloc] init];
        _errorTitleLabel.numberOfLines = 0;
        _errorTitleLabel.font = [UIFont systemFontOfSize:15];
        _errorTitleLabel.textAlignment = NSTextAlignmentCenter;
        _errorTitleLabel.textColor = MWHexColor(@"#555555");
        _errorTitleLabel.userInteractionEnabled = YES;
        _errorTitleLabel.text = [[MWConfigManager manager] objectForKey:@"click_retry" defaultValue:@"点击重试"];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh)];
        [_errorTitleLabel addGestureRecognizer:tap];
        [self.view addSubview:_errorTitleLabel];
        
        [_errorTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(15);
            make.right.equalTo(self.view).offset(-15);
            make.top.equalTo(self.errorImageView.mas_bottom).offset(10);
        }];
    }
    return _errorTitleLabel;
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

@end

